<?php
/**
 * 用户管理类
 *
 * @auther 大耳牛
 * 2016-12-31
 **/
namespace Home\Model;
use Think\Model;
class MemberModel extends Model{
	//定义表名称
	protected $tableName = 'member';
	
	/**
	 * 获取会员列表总数
	 *
	 **/
	public function getMemberListCount(){
		return $this->count();
	}
	
	/**
	 * 获取会员列表
	 *
	 **/
	public function getMemberList($page){
		return $this->alias('member')
					->join('left join momoda_users as users on member.user_id = users.user_id')
					->field('member.*, users.nickname')
					->order('member.checkin_time asc')
					->page($page, C('PAGE_SIZE'))
					->select();
	}
	
	public function getMemberListAll(){
		return $this->alias('member')
					->join('left join momoda_users as users on member.user_id = users.user_id')
					->field('member.*, users.nickname')
					->order('member.checkin_time asc')
					->select();
	}
	
	/**
	 * 客人信息保存
	 *
	 **/
	public function addMemberInfo($data){
		$this->data($data)->add();
	}
	
	/**
	 * 删除客人信息
	 * @param int $memberId 客人ID
	 **/
	public function delMemberInfo($memberId, $state){
		return $this->where(array('member_id' => $memberId))->setField('visible', $state);
	}
	
	/**
	 * 编辑客人信息
	 * @param int $memberId
	 * @param Array $data 编辑资料
	 **/
	public function editMemberInfo($memberId, $data){
		return $this->where(array('member_id' => $memberId))->save($data);
	}
	
	/**
	 * 查询客人详情
	 * @param int $memberId
	 **/
	public function getMemberInfoById($memberId){
		return $this->where(array('member_id' => $memberId, 'visible' => 1))->find();
	}
	
	/**
	 * 查询客人详情
	 * @param int $memberId
	 **/
	public function getMemberInfoByPhone($phone, $code){
		return $this->where(array(
			'member_phone' => $phone,
			'code' => $code,
			'visible' => 1
		))->order('member_id desc')->find();
	}
}